﻿
Imports elpmis
Imports webctrl

Namespace httpFunctions
    Public MustInherit Class jsgetById
        Inherits internalfunction

        Class parameters
            Public Const page As String = "page"
            Public Const inlineScript As String = "inlineScript"
            Public Const id As String = "id"
        End Class

        Private Shared m As iParametersMapping = Nothing

        Shared Sub New()
            initialMapping(m, parameters.page, parameters.id)
        End Sub

        Protected Sub New(ByVal name As String)
            MyBase.New(name, m)
        End Sub

        Protected MustOverride Overloads Function invokeImpl(ByVal ctx As context, _
                                                             ByVal inlineScript As inlineScript, _
                                                             ByVal id As String) As String

        Protected Overrides Function invoke(ByVal ctx As elpmis.context, ByRef output As bare_variable) As Boolean
            Dim id As String = Nothing
            If ctx.findVariableStr(parameters.id, id) Then
                Dim inlineScript As inlineScript = Nothing
                getinlinescript(ctx, inlineScript, parameters.page, parameters.inlineScript)
                output = New bare_variable(typeDefination.string, _
                                           invokeImpl(ctx, inlineScript, id))
                Return True
            Else
                raiseError("expect parameter " + parameters.id, errorHandle.errorType.user)
                Return False
            End If
        End Function
    End Class

    Public Class jsgetelementById
        Inherits jsgetById

        Public Sub New()
            MyBase.new("js.getelement.id")
        End Sub

        Protected Overrides Function invokeImpl(ByVal ctx As context, _
                                                ByVal inlineScript As inlineScript, ByVal id As String) As String
            Return getElementById.invoke(inlineScript, id)
        End Function
    End Class

End Namespace
